package cn.francis.chatplatform.modules.session.controller;

import cn.francis.chatplatform.modules.session.service.ChatSessionService;
import cn.francis.chatplatform.modules.session.vo.TestVO;
import cn.francis.chatplatform.modules.session.vo.TestVO2;
import cn.francis.chatplatform.modules.session.vo.TestVO3;
import cn.francis.common.utils.json.JsonUtil;
import com.alibaba.fastjson2.JSON;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 张俊辉
 */

@Slf4j
@RestController
@RequestMapping("test")
@RequiredArgsConstructor
public class TestController {

    private final ChatSessionService chatSessionService;

    @PostMapping("1")
    public void execute(@RequestBody @Valid TestVO testVO) throws Exception {
        log.info("入参 => {}", JsonUtil.toJson(testVO));
        System.out.println(testVO);
        chatSessionService.test(testVO.getTest());
    }

    @PostMapping("2")
    public TestVO2 execute2(@RequestBody @Validated TestVO2 testVO) throws Exception {
        log.info("入参 => {}", JSON.toJSONString(testVO));
        System.out.println(JSON.parseObject(JsonUtil.toJson(testVO), TestVO2.class));
        return testVO;
    }

    @PostMapping("3")
    public void execute3(@RequestBody @Valid TestVO testVO) throws Exception {
        log.info("入参 => {}", JsonUtil.toJson(testVO));
        System.out.println(testVO);
        chatSessionService.test3(testVO);
    }

    @PostMapping("4")
    public void execute4(@RequestBody TestVO3 testVO) throws Exception {
        log.info("入参 => {}", JsonUtil.toJson(testVO));
        System.out.println(testVO);
        chatSessionService.test4(testVO);
    }
}
